package com.romotc.qqrobot.webqq.qqInterfaceCall.dataProcessor;

import org.json.JSONObject;

import com.romotc.joyin.bean.CustomerService;
import com.romotc.json.tools.Jackson;
import com.romotc.qqrobot.bean.QQLogedin;
import com.romotc.qqrobot.bean.QQTask;
import com.romotc.qqrobot.webqq.bean.Get_friend_uin_ResponseBody;
import com.romotc.scache.RequestSpy;

public class Get_friend_uin_CheckFriendAndCustomerProcess implements
		DateProcessor {

	public static String Key_ResultNote = "Get_friend_uin_CheckFriendAndCustomerProcess_ResultNote";
	public static String Key_Result = "Get_friend_uin_CheckFriendAndCustomerProcess_Result";
	public static String QQTaskObject = "QQTaskObject";

	@Override
	public JSONObject processResponse(QQLogedin loginQQ, RequestSpy rqSpy,
			JSONObject reqDataObj) throws Exception {
		QQTask qTask = (QQTask)reqDataObj.get(QQTaskObject);
		
		// {"retcode":0,"result":{"uiuin":"","account":819512594,"uin":1924492178}}
		String resBody = rqSpy.getResBody();
		Get_friend_uin_ResponseBody resObject = Jackson.getObjectMaper().readValue(resBody, Get_friend_uin_ResponseBody.class);
		if(resObject.getRetcode() == 0 && resObject.getResult() != null) {
			
			//不正常的返回信息：QQ号
			if(resObject.getResult().getAccount() < 10000) {
				qTask.setTaskRunNote("get_friend_uin2Result:{" + resBody + "}" );
				qTask.setTaskRunResult(qTask.RunResult_Error_DotTry);
			}
			
			CustomerService.checkFriendsAndCustomer(resObject.getResult(), qTask);
		}else {
			qTask.setTaskRunNote("get_friend_uin2Result:{" + resBody + "}");
			qTask.setTaskRunResult(QQTask.RunResult_NeedReTry);
		}
		return reqDataObj;
	}

	private static Get_friend_uin_CheckFriendAndCustomerProcess instance;
	
	public static synchronized Get_friend_uin_CheckFriendAndCustomerProcess getInstance() {
		if(instance == null)
			instance = new Get_friend_uin_CheckFriendAndCustomerProcess();
		return instance;
	}

}
